<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList">
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay==1" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="addAddress" type="primary" icon="el-icon-edit"></el-button>
            <el-button size="mini" @click="process" type="success" icon="el-icon-location"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页功能 -->
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
    title="修改地址"
    :visible.sync="addressDialogVisible"
    width="50%" @close="addAddressClose">
    <el-form ref="addressFormRef" :model="addressForm" label-width="80px">
      <el-form-item label="省市区/县" prop="addAddress">
        <el-cascader
        v-model="addressForm.addAddress"
        :options="addressData"
        :props="{ expandTrigger: 'hover' }"
        @change="handleChange"></el-cascader>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="addressDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="addressDialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
  <!-- 物流进度 -->
  <el-dialog
  title="物流进度"
  :visible.sync="processDialogVisible"
  width="50%">
  <el-timeline :reverse="reverse">
    <el-timeline-item
      v-for="(activity, index) in processData"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
  </el-dialog>
  </div>
</template>

<script>
import addressData from './citydata'
export default {
  data(){
    return {
      queryInfo:{
        query:'',
        // 当前页码
        pagenum:1,
        // 每页显示条数
        pagesize:10
      },
      total:0,
      orderList:[],
      // 地址对话框的显示与隐藏
      addressDialogVisible:false,
      // 修改地址表单
      addressForm:{},
      // 地址数据
      addressData:addressData,
      processDialogVisible:false,
      // 物流进度数据
      processData:[],
      // 物流进度排序
      reverse:true,
    }
  },
  created(){
    // 获取订单列表
    this.getOrderList()
  },
  methods:{
    // 获取订单列表
    async getOrderList(){
      const {data:res} = await this.$http.get('orders',{params:this.queryInfo})
      if(res.meta.status !== 200){
        this.$message.error('获取订单列表错误')
      }
      this.total = res.data.total
      this.orderList = res.data.goods
      console.log(res.data);
      
    },
    // 当前页显示条数
    handleSizeChange(val){
      this.queryInfo.pagesize = val
      this.getOrderList()
    },
    // 当前页改变
    handleCurrentChange(val){
      this.queryInfo.pagenum = val
      this.getOrderList()
    },
    // 更改地址
    addAddress(){
      this.addressDialogVisible = true
    },
    // 处理地址级联选择框
    handleChange(val){
      console.log(val);
      
    },
    // 关闭添加地址的dialog
    addAddressClose(){
      this.$refs.addressFormRef.resetFields()
    },
    // 物流进度查询
    async process(){
      const {data:res} = await this.$http.get('/kuaidi/1106975712662')
      if(res.meta.status !== 200){
        this.$message.error('获取物流进度错误')
      }
      console.log(res.data);
      this.processDialogVisible = true
      this.processData = res.data
    }
  },
  
}
</script>


<style lang="less" scoped>
.el-cascader{
  width: 100%;
}
</style>